/* element form表单验证 */

// 手机号
const phone: RegExp = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/
// 座机
const tel: RegExp = /^((\d{3,4}-\d{7,8})|(\d{7}-\d{1,12})|(\d{8}-\d{1,11})|(\d{11}-\d{1,8})|(\d{7,8})|(\d{11,20})|(\d{3}-\d{8}-\d{1,7})|(\d{3}-\d{7}-\d{1,8})|(\d{4}-\d{7}-\d{1,7})|(\d{4}-\d{8}-\d{1,6}))$/
// 座机或手机号
const telPhone: RegExp = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(16[2|6|7])|(18[0-9])|(17([0-1]|[3]|[5-8]))|(19[1|8|9]))\d{8}$|^((\d{3,4}-\d{7,8})|(\d{7}-\d{1,12})|(\d{8}-\d{1,11})|(\d{11}-\d{1,8})|(\d{7,8})|(\d{11,20})|(\d{3}-\d{8}-\d{1,7})|(\d{3}-\d{7}-\d{1,8})|(\d{4}-\d{7}-\d{1,7})|(\d{4}-\d{8}-\d{1,6}))$/
// 身份证
const card: RegExp = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/
// 邮政编码
const postal: RegExp = /[1-9]\d{5}(?!\d)/
// QQ
const qq: RegExp = /^[1-9][0-9]{4,11}$/
// 邮箱
const email: RegExp = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/
// url
const url: RegExp = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/
// ip
const IP: RegExp = /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/
// 数字和小数点
const num: RegExp = /^\d+$|^\d*\.\d+$/g
const money: RegExp = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
// 编号（数字、下划线、字母）
const serial: RegExp = /^[0-9a-zA-Z_]{1,}$/

/* 可以为空 不为空时不能有特殊字符 */
export const IsNull = (message: string, ev = 'blur'): any[] => [
  { required: false, message, trigger: ev },
  { pattern: /^[^'"<>%\\]+$/, message: '不能含有特殊字符', trigger: ev }
]
/*
* 不能为空
* */
export const IsnotNull = (message: string, ev = 'blur'): any[] => [
  { required: true, message, trigger: ev },
  { pattern: /^[^'"<>%\\]+$/, message: '不能含有特殊字符', trigger: ev }
]
/* 数字下划线字母不包含特殊符号 */
export const IsStrNotSymbol = (message?: string): any[] => [
  { pattern: serial, message: message ?? '只能输入数字下划线和英文字母', trigger: 'blur' }
]
/* 范围限制 */
export const minMaxLength = (min = 0, max = 15, ev = 'blur'): any[] => [
  { min, max, message: `只能输入${min}到${max}个字符`, trigger: ev }
]
/**
 * 验证手机号
 * @type {Array}
 */
export const IsPhone = (message?: string, ev = 'blur'): any[] => [
  { pattern: phone, message: message ?? '手机号格式不正确', trigger: ev }
]

/**
 * 验证座机号
 * @type {Array}
 */
export const IsPlane = (message?: string, ev = 'blur'): any[] => [
  { pattern: tel, message: message ?? '电话号码格式不正确', trigger: ev }
]
/**
 * 验证座机或手机号
 * @type {Array}
 */
export const IsPlaneAndPhone = (message?: string, ev = 'blur'): any[] => [
  { pattern: telPhone, message: message ?? '联系方式格式不正确', trigger: ev }
]
/**
 * 验证QQ
 * @type {Array}
 */
export const IsQQ = (message?: string, ev = 'blur'): any[] => [
  { pattern: qq, message: message ?? 'qq号格式不正确', trigger: ev }
]
/**
 * 验证邮箱
 * @type {Array}
 */
export const IsEmail = (message?: string, ev = 'blur'): any[] => [
  { pattern: email, message: message ?? '邮箱格式不正确', trigger: ev }
]
/**
 * 验证身份证
 * @type {Array}
 */
export const IsIdCard = (message?: string, ev = 'blur'): any[] => [
  { pattern: card, message: message ?? '身份证格式不正确', trigger: ev }
]
/**
 * 验证邮政编码
 * @type {Array}
 */
export const IsPostalCode = (message?: string, ev = 'blur'): any[] => [
  { pattern: postal, message: message ?? '邮政编码格式不正确', trigger: ev }
]
/**
 * 验证url
 * @type {Array}
 */
export const IsUrl = (message?: string, ev = 'blur'): any[] => [
  { pattern: url, message: message ?? 'url格式不正确', trigger: ev }
]
/**
 * 验证IP
 * @type {Array}
 */
export const IsIP = (message?: string, ev = 'blur'): any[] => [
  { pattern: IP, message: message ?? 'IP格式不正确', trigger: ev }
]
/**
 * @description : 验证是否为数字和小数点
 */

export const IsNum = (message?: string, ev = 'blur'): any[] => [
  { pattern: num, message: message ?? '只能输入数字和小数点', trigger: ev }
]
/**
 * @description : 验证是否为money
 */

export const IsMoney = (message?: string, ev = 'blur'): any[] => [
  { pattern: money, message: message ?? '只能输入数字和小数点,且最多保留两位小数', trigger: ev }
]
